<?php
namespace app\admin\controller;
use app\admin\model\DemandOptions;
use app\admin\model\Demand as Demands;
use think\Request;

class Demand extends Base
{
    protected function _initialize(){
        $this->checkLogin();
        $this->menuLoad();
    }
    public function index(){
        return $this->fetch('public/help');
    }

    public function demandList(){
        $demandOptions = new Demands();
        $where['id'] = ['neq','0'];
        $rs = $demandOptions->getAll($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function demandOption(Request $request){
        $demandOptions = new DemandOptions();
        $where['id'] = 1;
        if($request->post()){
            $data = $request->post();
            $rs = $demandOptions->edit($where,$data);
            if($rs){
                return $this->success('修改成功');
            }else{
                return $this->error('修改失败');
            }
        }
        $rs = $demandOptions->getOne($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    //头部未接待数量
    public function getNum(){
        $demand = new Demands();
        $where['status'] = 0;
        $res['num'] = $demand->totalNumWhere($where);
        echo json_encode($res);
    }
}